// 墙canvas子类
import canvasAbstract from './canvasAbstract';
import config from '../config';
import tankModel from '../model/tank';
import position from '../service/position';

export default  new (class tank extends canvasAbstract implements ICanvas{
  name = 'tank';
  setIntervalID: number = 0;
  num(): number {
    return config.tank.num;
  }
  model(): ModelInterface {
    return tankModel;
  }
  render() {
    this.createModel();
    // 遍历绘制对应模型
    this.setIntervalID = setInterval(() => {
      this.renderModel();
    }, config.tank.speed);
  }
  protected createModel() {
    // 遍历坐标list创建并绘制对应模型
    let i = 0;
    for (; i < this.num(); i++) {
      let model = this.model();
      let pos = position.position();
      let instance = new model(pos.x, 0);
      this.modelist.push(instance);
    };
  };
  // 渲染模型
  renderModel() {
    this.canvas!.clearRect(0, 0, config.canvas.width, config.canvas.hieght);
    super.renderModel();
  };
  stop() {
    clearInterval(this.setIntervalID);
  };
})('tank');